package com.pdg.mcplugin.recyclotron;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.material.MaterialData;

public enum Recipes {
	BIRCH_SAPLINGS_TO_STICKS(new MaterialData(Material.SAPLING, TreeSpecies.BIRCH.getData()),new MaterialData(Material.STICK),1,9,1,1),
	OAK_SAPLINGS_TO_STICKS(new MaterialData(Material.SAPLING, TreeSpecies.GENERIC.getData()),new MaterialData(Material.STICK),1,9,1,1),
	JUNGLE_SAPLINGS_TO_STICKS(new MaterialData(Material.SAPLING, TreeSpecies.JUNGLE.getData()),new MaterialData(Material.STICK),1,9,1,1),
	SPRUCE_SAPLINGS_TO_STICKS(new MaterialData(Material.SAPLING, TreeSpecies.REDWOOD.getData()),new MaterialData(Material.STICK),1,9,1,1),
	FENCE_TO_STICKS(new MaterialData(Material.FENCE),new MaterialData(Material.STICK),1,9,6,4),
	BOAT_TO_PLANKS(new MaterialData(Material.BOAT),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),1,9,5,2),
	BENCH_TO_PLANKS(new MaterialData(Material.WORKBENCH),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),1,9,4,2),
	ROTTEN_FLESH_TO_BONE_MEAL(new MaterialData(Material.ROTTEN_FLESH),new MaterialData(Material.INK_SACK,(byte)(15-DyeColor.WHITE.getDyeData())),1,9,1,4),
	LADDER_TO_STICKS(new MaterialData(Material.LADDER),new MaterialData(Material.STICK),1,9,7,6),
	WOOL_TO_STRING(new MaterialData(Material.WOOL,DyeColor.WHITE.getDyeData()),new MaterialData(Material.STRING),1,9,1,2),
	BIRCH_STAIRS_TO_PLANKS(new MaterialData(Material.BIRCH_WOOD_STAIRS),new MaterialData(Material.WOOD,TreeSpecies.BIRCH.getData()),1,9,3,4),
	OAK_STAIRS_TO_PLANKS(new MaterialData(Material.WOOD_STAIRS),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),1,9,3,4),
	JUNGLE_STAIRS_TO_PLANKS(new MaterialData(Material.JUNGLE_WOOD_STAIRS),new MaterialData(Material.WOOD,TreeSpecies.JUNGLE.getData()),1,9,3,4),
	SPRUCE_STAIRS_TO_PLANKS(new MaterialData(Material.SPRUCE_WOOD_STAIRS),new MaterialData(Material.WOOD,TreeSpecies.REDWOOD.getData()),1,9,3,4),
	BIRCH_SLAB_TO_PLANKS(new MaterialData(Material.WOOD_STEP,TreeSpecies.BIRCH.getData()),new MaterialData(Material.WOOD,TreeSpecies.BIRCH.getData()),1,9,1,4),
	OAK_SLAB_TO_PLANKS(new MaterialData(Material.WOOD_STEP,TreeSpecies.GENERIC.getData()),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),1,9,1,4),
	JUNGLE_SLAB_TO_PLANKS(new MaterialData(Material.WOOD_STEP,TreeSpecies.JUNGLE.getData()),new MaterialData(Material.WOOD,TreeSpecies.JUNGLE.getData()),1,9,1,4),
	SPRUCE_SLAB_TO_PLANKS(new MaterialData(Material.WOOD_STEP,TreeSpecies.REDWOOD.getData()),new MaterialData(Material.WOOD,TreeSpecies.REDWOOD.getData()),1,9,1,4),
	WOOD_SHOVEL_TO_PLANKS(new MaterialData(Material.WOOD_SPADE),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),3,9,1,2),
	STONE_SHOVEL_TO_COBBLE(new MaterialData(Material.STONE_SPADE),new MaterialData(Material.COBBLESTONE),3,9,1,2),
	IRON_SHOVEL_TO_IRON_ORE(new MaterialData(Material.IRON_SPADE),new MaterialData(Material.IRON_ORE),3,9,1,2),
	GOLD_SHOVEL_TO_GOLD_ORE(new MaterialData(Material.GOLD_SPADE),new MaterialData(Material.GOLD_ORE),3,9,1,2),
	DIAMOND_SHOVEL_TO_DIAMONDS(new MaterialData(Material.DIAMOND_SPADE),new MaterialData(Material.DIAMOND),3,9,1,2),
	WOOD_HOE_TO_PLANKS(new MaterialData(Material.WOOD_HOE),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),3,9,2,2),
	STONE_HOE_TO_COBBLE(new MaterialData(Material.STONE_HOE),new MaterialData(Material.COBBLESTONE),3,9,2,2),
	IRON_HOE_TO_IRON_ORE(new MaterialData(Material.IRON_HOE),new MaterialData(Material.IRON_ORE),3,9,2,2),
	GOLD_HOE_TO_GOLD_ORE(new MaterialData(Material.GOLD_HOE),new MaterialData(Material.GOLD_ORE),3,9,2,2),
	DIAMOND_HOE_TO_DIAMONDS(new MaterialData(Material.DIAMOND_HOE),new MaterialData(Material.DIAMOND),3,9,2,2),
	WOOD_PICK_TO_PLANKS(new MaterialData(Material.WOOD_PICKAXE),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),3,9,3,2),
	STONE_PICK_TO_COBBLE(new MaterialData(Material.STONE_PICKAXE),new MaterialData(Material.COBBLESTONE),3,9,3,2),
	IRON_PICK_TO_IRON_ORE(new MaterialData(Material.IRON_PICKAXE),new MaterialData(Material.IRON_ORE),3,9,3,2),
	GOLD_PICK_TO_GOLD_ORE(new MaterialData(Material.GOLD_PICKAXE),new MaterialData(Material.GOLD_ORE),3,9,3,2),
	DIAMOND_PICK_TO_DIAMONDS(new MaterialData(Material.DIAMOND_PICKAXE),new MaterialData(Material.DIAMOND),3,9,3,2),
	WOOD_SWORD_TO_PLANKS(new MaterialData(Material.WOOD_SWORD),new MaterialData(Material.WOOD,TreeSpecies.GENERIC.getData()),3,9,2,2),
	STONE_SWORD_TO_COBBLE(new MaterialData(Material.STONE_SWORD),new MaterialData(Material.COBBLESTONE),3,9,2,2),
	IRON_SWORD_TO_IRON_ORE(new MaterialData(Material.IRON_SWORD),new MaterialData(Material.IRON_ORE),3,9,2,2),
	GOLD_SWORD_TO_GOLD_ORE(new MaterialData(Material.GOLD_SWORD),new MaterialData(Material.GOLD_ORE),3,9,2,2),
	DIAMOND_SWORD_TO_DIAMONDS(new MaterialData(Material.DIAMOND_SWORD),new MaterialData(Material.DIAMOND),3,9,2,2),
	;
	private static final String FORMAT_INGREDIENT_NAME = "%s_%d";
	private final MaterialData input;
	private final MaterialData output;
	private int minimum;
	private int maximum;
	private int multiplier;
	private int divisor;
	Recipes(MaterialData theInput,MaterialData theOutput,int theMinimum,int theMaximum, int theMultiplier, int theDivisor){
		input = theInput;
		output = theOutput;
		minimum = theMinimum;
		maximum = theMaximum;
		multiplier = theMultiplier;
		divisor = theDivisor;
	}
	public MaterialData getInput(){
		return input;
	}
	public MaterialData getOutput(){
		return output;
	}
	public int getMinimum(){
		return minimum;
	}
	public int getMaximum(){
		return maximum;
	}
	public int getMultipler(){
		return multiplier;
	}
	public int getDivisor(){
		return divisor;
	}
	public List<Recipe> getRecipes(){
		List<Recipe> theRecipes = new ArrayList<Recipe>();
		for(int theCount=getMinimum();theCount<=getMaximum();++theCount){
			Recipe theRecipe = getRecipe(theCount);
			if(theRecipe!=null){
				theRecipes.add(theRecipe);
			}
		}
		return theRecipes;
	}
	private Recipe getRecipe(int theCount) {
		int theAmount = theCount * getMultipler() / getDivisor();
		if(theAmount<1) return null;
		ShapelessRecipe theRecipe = new ShapelessRecipe(getOutput().toItemStack(theAmount));
		while(theCount>0){
			theRecipe.addIngredient(getInput());
			theCount--;
		}
		return theRecipe;
	}
	public String getIngredientName(){
		return String.format(FORMAT_INGREDIENT_NAME, getInput().getItemType().toString(),getInput().getData());
	}
}
